<?php
/**
 * User: xuanbang.wen
 * Date: 2019/8/29
 */

namespace App\Web\Model;


use App\Web\Facades\UserAuth;
use EchoPHP\Facades\Db;

class ResumeTag extends Model {
    private $tablename = 'ResumeTag';

    public function show($resumeId){
        $sql = 'select id as tagId,content from '.$this->tablename.' where resumeid = ? and status != ? order by id desc' ;
        return Db::select($sql,[$resumeId,'06']);
    }
    public function create($params){
        $sql = 'select 1 from ' . $this->tablename . ' where resumeid = ? and content = ? and status = ? limit ?';
        if (Db::selectOne($sql, [$params['resumeId'], $params['content'], '01', 1])) {
            return -1;
        }
        $sql = 'INSERT INTO ' . $this->tablename . ' (resumeid,content,creator,createdate,updator,updatedate,status)
                value (?,?,?,NOW(),?,NOW(),?)';
        $var = [
            $params['resumeId'],
            $params['content'],
            $params['userid'],
            $params['userid'],
            '01',
        ];
        return Db::insert($sql,$var);
    }

    public function softDelete($tagId){
        $sql = 'update ' . $this->tablename . ' set status = ?,updator = ?,updatedate = NOW()
        where id = ?';
        $var = ['06',UserAuth::getLoginId(), $tagId];
        return Db::update($sql, $var);
    }
}